var imageDegree = 90;

function init() {
	_initHeader();
	
	var array = new Array();
	
	array.push("takePicture");
	array.push("getPicture");
	array.push("resizePicture");
	array.push("rotateImage");
	array.push("getImageOrientation");
	array.push("resizeAndRotateForward");
	
	draw_list(array);
}

function setOnListClickHandler(idx) {
	switch(idx) {
		case 0 :
			testTakePicture();
		break;
		
		case 1 :
			testGetPicture();
		break;
		
		case 2 :
			testResizePicture();
		break;
		
		case 3 :
			testRotateImage();
		break;
		
		case 4 :
			testGetImageOrientation();
		break;
		
		case 5 :
			testResizeAndRotateForward();
		break;
		
		default :
		break;
	}
}

/*
 * takePicture
 */
function testTakePicture() {
	multimedia.takePicture(takePictureSuccessCallback, takePictureErrorCallback);
}

function takePictureSuccessCallback(pictureInfo) {
	notifySuccess("takePicture");
	
	document.getElementById("picture").src = pictureInfo.path;
}

function takePictureErrorCallback(errorMessage) {
	notifyError("takePicture", errorMessage);
}

/*
 * getPicture
 */
function testGetPicture() {
	multimedia.getPicture(getPictureSuccessCallback, getPictureErrorCallback);
}

function getPictureErrorCallback(errorMessage) {
	notifyError("getPicture", errorMessage);
}

/*
 * resizePicture
 */
function testResizePicture() {
	multimedia.getPicture(getForResizePictureSuccessCallback, getPictureErrorCallback);
}

function getForResizePictureSuccessCallback(path) {
	var resizePictureInfo = {
		"path" : path,
		"width" : 50,
		"height" : 50,
		"overwrite" : false
	};
	
	multimedia.resizePicture(resizePictureInfo, resizePictureSuccessCallback);
}

function resizePictureSuccessCallback(path) {
	notifySuccess("resizePicture");
	document.getElementById("resizedPicture").src = path;
}

/*
 * rotateImage
 */
function testRotateImage() {
	imageDegree = prompt("사진을 회전할 각도를 입력하세요.", imageDegree);
	
	if(imageDegree)
		multimedia.getPicture(getForRotatePictureSuccessCallback, getPictureErrorCallback);
}

function getForRotatePictureSuccessCallback(path) {
	var rotateImageInfo = {
		"path" : path,
		"degree" : imageDegree,
		"overwrite" : false
	};
	
	multimedia.rotateImage(rotateImageInfo, rotateImageSuccessCallback);
}

function rotateImageSuccessCallback(path) {
	notifySuccess("rotateImage");
	document.getElementById("rotateImage").src = path;
}

/*
 * getImageOrientation
 */
function testGetImageOrientation() {
	multimedia.getPicture(orientationSuccessCallback, getPictureErrorCallback);
}

function orientationSuccessCallback(path) {
	multimedia.getImageOrientation(path, getImageOrientaionSuccessCallback);
}

function getImageOrientaionSuccessCallback(imageOrientationInfo) {
	notifySuccess("getImageOrientation");
	alert("degree: " + imageOrientationInfo.degree);
}

function getPictureSuccessCallback(path) {
	notifySuccess("getPicture");
	document.getElementById("picture").src = path;
}

/*
 * resizeAndRotateForward
 */
function testResizeAndRotateForward() {
	multimedia.getPicture(getForResizeAndRotateSuccessCallback, getForResizeAndRotateErrorCallback);
}

function getForResizeAndRotateSuccessCallback(path) {

	var size = {
		"width" : 30,
		"height" : 30
	};
	var multimediaExtension = new MultimediaExtension();
	
	multimediaExtension.resizeAndRotateForward(path, size, reseizeAndRotateCallback);
}

function getForResizeAndRotateErrorCallback(error) {
	log.log("getPictureErrorCallback!!! error: " + error);
}

function reseizeAndRotateCallback(path) {
	document.getElementById("rotateImage").src = path;
	notifySuccess("resizeAndRotateForward");
}